/**
 * Social Subscriptions
 * Implements the same CRUD terminology
 *
 * @author Seth
 * @version 0.1
 */
Social.Subscriptions = function(){
	var s = {},
		page = 1,

		// create (C)
		_create = function() {
	    	Petolio.ajax({
				url: 'social/create',
				type: 'post',
				data: {id: s.id, scope: s.scope, plugin: 'subscriptions'},
				cache: false,
				success: function (x) {
					_read();
				}
			});

		// read (R)
		},	_read = function() {
	    	Petolio.ajax({
				url: 'social/read',
				type: 'post',
				data: {id: s.id, scope: s.scope, plugin: 'subscriptions'},
				cache: false,
				success: function (x) {
					s.loc.html(x.html);
					_bind();
					Social.done();
				}
			});

		// update (U)
		},	_update = function() {
			// not used

		// delete (D)
		},	_delete = function(e) {
			var id = $(this).attr('rel');

	    	Petolio.ajax({
				url: 'social/delete',
				type: 'post',
				data: {x: id, id: s.id, scope: s.scope, plugin: 'subscriptions'},
				cache: false,
				success: function (x) {
					_read();
				}
			});

		// bind events
		},	_bind = function() {
			s.loc.find('[class="subscription_add"]').click(_create);
			s.loc.find('[class="subscription_remove"]').click(_delete);

		// plugin constructor
		},	__construct = function(win, params) {
			s.loc = win.find('.subscriptions');
			s.id = params.id;
			s.scope = params.scope;
			s.win = win;

			_read();
		};

	// public
	return {
		load: __construct
	};
}();